<?php
namespace app\index\controller;
use think\Controller;

class Lists extends Base
{
    public function index()
    {
	  $firstCatIds = $data = $orders = [];

	  
	  //获取一级分类	
	  $categorys = model('Category')->getNormalCategorysByParentId();
	  foreach($categorys as $category){
		  $firstCatIds[] = $category->id;
		  }
		
	  $id = input('id', 0, 'intval');
	  
	  if(in_array($id, $firstCatIds)){//一级分类
		  $categoryParentId = $id;
		  $data['category_id'] = $id;
		  
		  }elseif($id){//二级分类
			  $category = model('Category')->get($id);
			  if(!$category || $category->status != 1){
				  $this->error('数据不合法');
				  }
			  $categoryParentId = $category->parent_id;
			  $data['se_category_id'] = $id;
			  
			  }else{//未传递默认为0
				  $categoryParentId = 0;
				  }
		$sedcategorys= [];
		//获取子分类数据
		if($categoryParentId){
			$sedcategorys = model('Category')->getNormalCategorysByParentId($categoryParentId);
			
			}
		//排序
		$order_sales = input('order_sales', '');
		$order_price = input('order_price', '');
		$order_time = input('order_time', '');
		
		if(!empty($order_sales)){
			$orderflag = 'order_sales';
			$orders['order_sales'] = $order_sales;
			
			}elseif(!empty($order_price)){
			$orderflag = 'order_price';
			$orders['order_price'] = $order_price;
			
			}elseif(!empty($order_time)){
			$orderflag = 'order_time';
			$orders['order_time'] = $order_time;
			
			}else{
			$orderflag = '';
	
			}
		
		$data['city_id'] = $this->city->id;
		
		
		//根据查询条件  查询数据
		$deals = model('Deal')->getDealByConditions($data, $orders);
		
		
		
		
		return $this->fetch('', [
		    'categorys' => $categorys,
			'sedcategorys' => $sedcategorys,
			'categoryParentId' => $categoryParentId,
			'id' => $id,
			'orderflag' => $orderflag,
			'deals' => $deals,
		
		]);
    }
}










?>